package lib.common.use;




// 上传图片剪切
// 保存和上传录音
// https
// 弹出信息从顶层下来，动画；

import com.app.dialog.DialogLoading_sina;
import com.app.dialog.DialogLoading_weixin;
import com.app.dialog.DialogProgressPercentage;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class MainActivity extends FragmentActivity implements
		ActionBar.OnNavigationListener {
	
	
	MainActivity activity = this;
	

	/**
	 * The serialization (saved instance state) Bundle key representing the
	 * current dropdown position.
	 */
	private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// Set up the action bar to show a dropdown list.
		final ActionBar actionBar = getActionBar();
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

		// Set up the dropdown list navigation in the action bar.
		actionBar.setListNavigationCallbacks(
		// Specify a SpinnerAdapter to populate the dropdown list.
				new ArrayAdapter<String>(actionBar.getThemedContext(),
						android.R.layout.simple_list_item_1,
						android.R.id.text1, new String[] {
								getString(R.string.title_dialog_1),
								getString(R.string.title_dialog_2),
								getString(R.string.title_dialog_3), 
								"对话框4",
								"HomeActivity",
								"FucActivity",
								"RefreshActivity",
								"listview相关技巧",
								"自定义view",
								"对话框显示时间间隔",
								"设计图像素处理"
								}), this);
		
		
		//
		
		
		
		
		
	}

	@Override
	public void onRestoreInstanceState(Bundle savedInstanceState) {
		// Restore the previously serialized current dropdown position.
		if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
			getActionBar().setSelectedNavigationItem(
					savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
		}
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		// Serialize the current dropdown position.
		outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar()
				.getSelectedNavigationIndex());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onNavigationItemSelected(int position, long id) {
		// When the given dropdown item is selected, show its contents in the
		// container view.
		Fragment fragment = new DummySectionFragment();
		Bundle args = new Bundle();
		args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
		fragment.setArguments(args);
		getSupportFragmentManager().beginTransaction()
				.replace(R.id.container, fragment).commit();
		return true;
	}


	
	
	Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			
			if(msg.what == 1){
				DialogLoading_weixin.ShowTitleDialog(activity, "123");
			}
			else if(msg.what == 2){
				DialogLoading_weixin.ShowNoTitleDialog(activity);
			}
			else if(msg.what == 3){
				
				DialogLoading_sina.showLoadingDialog(activity);
			}
			else if(msg.what == 4){
				DialogProgressPercentage.ShowTitleDialog( activity );
			}
			else if(msg.what == 5){
				
				Intent intent = new Intent(activity, HomeActivity.class);
				startActivity(intent);
			}
			else if(msg.what == 6){
				
				Intent intent = new Intent(activity, FucActivity.class);
				startActivity(intent);
				
			}
			else if(msg.what == 7){
				Intent intent = new Intent(activity, RefreshActivity.class);
				startActivity(intent);
				
			}
			else if(msg.what == 8){
				Intent intent = new Intent(activity, ListActivity.class);
				startActivity(intent);
				
			}
			else if(msg.what == 9){
				Intent intent = new Intent(activity, DIYViewActivity.class);
				startActivity(intent);
			}
			else if(msg.what == 10){
				Intent intent = new Intent(activity, DialogElapsedTimeActivity.class);
				startActivity(intent);
			}
			else if(msg.what == 11){
				Intent intent = new Intent(activity, PixelActivity.class);
				startActivity(intent);
			}
			
			
		};
	};
	

	
	/**
	 * A dummy fragment representing a section of the app, but that simply
	 * displays dummy text.
	 */
	@SuppressLint("ValidFragment")
	class DummySectionFragment extends Fragment {
		/**
		 * The fragment argument representing the section number for this
		 * fragment.
		 */
		public static final String ARG_SECTION_NUMBER = "section_number";


		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.fragment_main_dummy,
					container, false);
			
			/*
			TextView dummyTextView = (TextView) rootView
					.findViewById(R.id.section_label);
			dummyTextView.setText(Integer.toString(getArguments().getInt(
					ARG_SECTION_NUMBER)));
			*/
			
			int number = getArguments().getInt( ARG_SECTION_NUMBER );
			handler.sendEmptyMessage( number );
			
			
			return rootView;
		}
		
		@Override
		public void onResume() {
			// TODO Auto-generated method stub
			super.onResume();
			
			//int number = getArguments().getInt( ARG_SECTION_NUMBER );
			//handler.sendEmptyMessage( number );
		}
		
		
	}
	 
	
	
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
	//	super.onBackPressed();
		
		AlertDialog.Builder builder = new Builder(this);
		builder = builder.setTitle("是否退出？");
		builder = builder.setPositiveButton("确定", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
				System.exit(0);
				
			}
		});
		builder = builder.setNegativeButton("取消", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface arg0, int arg1) {
				// TODO Auto-generated method stub
				
			}
		});
		
		builder.show();
	}	
	
	

}







